package com.shiyang.seckill.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * @author shiyang
 * @create 2020-07-18 2:50 下午
 */
@Service
public class RedisPoolFactory {

    @Autowired
    private RedisConfig redisConfig;

    @Bean
    public JedisPool jedisPoolFactory() {
//        JedisPoolConfig config = new JedisPoolConfig();
//        config.setTestOnBorrow(false);
//        config.setMaxTotal(redisConfig.getMaxActive());
//        config.setMaxIdle(redisConfig.getMaxIdle());
//        config.setMaxWaitMillis(redisConfig.getMaxWait() * 1000);
//        JedisPool jedisPool =
//                new JedisPool(config, redisConfig.getHost(), redisConfig.getPort(), redisConfig.getTimeout() * 1000);
//        return jedisPool;
        return new JedisPool(new JedisPoolConfig(), "127.0.0.1", 6379, 2000);
    }
}
